package pack0924;

public class DemoC {

    //1377760
    private static void a() {
        int[] arr = new int[1000000];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) (Math.random() * 100000 + 1);
        }
        System.out.println("开始进行冒泡排序法");
        long begin = System.currentTimeMillis();
        for (int i = 0; i < arr.length - 1; i++) {
            for (int j = 0; j < arr.length - 1 - i; j++) {
                if (arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }
        }
        long end = System.currentTimeMillis();
        System.out.println("结束冒泡排序法");
        long time = end - begin;
        System.out.println("冒泡排序法花费时间是：" + time + "毫秒");
    }

    // 2596
    private static void b() {
        int[] arr = new int[100000];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) (Math.random() * 100000 + 1);
        }
        System.out.println("开始进行选择排序法");
        long begin = System.currentTimeMillis();
        for (int j = 0; j < arr.length - 1; j++) {
            int min = arr[j];
            int minIndex = j;
            for (int i = j + 1; i < arr.length; i++) {
                if (min > arr[i]) {
                    min = arr[i];
                    minIndex = i;
                }
            }
            // 交换元素（最小值和第`一`个）
            int temp = arr[j];
            arr[j] = arr[minIndex];
            arr[minIndex] = temp;
        }
        long end = System.currentTimeMillis();
        System.out.println("结束选择排序法");
        long time = end - begin;
        System.out.println("选择排序法花费时间是：" + time + "毫秒");
    }

    // 6025
    private static void c() {
        int[] arr = new int[100000];
        for (int i = 0; i < arr.length; i++) {
            arr[i] = (int) (Math.random() * 100000 + 1);
        }
        System.out.println("开始进行插入排序法");
        long begin = System.currentTimeMillis();
        for (int i = 1; i < arr.length; i++) {
            for (int j = 0; j < i; j++) {
                if (arr[i] < arr[j]) {
                    int temp = arr[i]; // 33
                    System.arraycopy(arr, j, arr, j + 1, (i - j));
                    arr[j] = temp;
                }
            }
        }
        long end = System.currentTimeMillis();
        System.out.println("结束插入排序法");
        long time = end - begin;
        System.out.println("选择插入法花费时间是：" + time + "毫秒");
    }

    public static void main(String[] args) {
        a();
    }
}